<section class="content-header">
   <h1>
      <b>{$header}
          <small>>>{$desc}</small>
      </b>
    </h1>
</section>
<section class="content" id="pjax-container">
  <div class="box">
      <div class="box-header with-border">
        <h3 class="box-title"><b>短信模板列表</b></h3>&nbsp;&nbsp;共{$dataNum}条记录
            <form action="{:url('SnsMsg/msgTemplateLists', ['query' => 1])}" method="get" class="form-inline pull-right" role="form" data-pjax>
                <div class="form-group">
                    <label for="field-other" class="label-control">模板名称&nbsp;</label>
                    <input type="text" name="name" id="" class="form-control input-sm" value="" placeholder="输入模板名称">
                </div>
                <div class="form-group">
                    <label for="field-other" class="label-control">&nbsp;模板编号&nbsp;</label>
                    <input type="text" name="id" id="" class="form-control input-sm" value="" placeholder="输入模板编号">
                </div>
                <div class="form-group">
                    <label for="field-status" class="control-label">&nbsp;模板状态&nbsp;</label>
                    <select name="status" class="form-control input-sm">
                        <option value="-1">未选择</option>
                        <option value="1">在用</option>
                        <option value="0">停用</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="field-page" class="control-label">&nbsp;每页记录:&nbsp;</label>
                    <select name="pageSize" class="form-control input-sm">
                        <option value="10">10条</option>
                        <option value="20">20条</option>
                        <option value="30">30条</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-success btn-sm">查询</button>
            </form>
      </div>
      <div class="box-body">
          <table class="table table-hover table-border">
            <thead>
              <tr>
                <th>模板编号</th>
                <th>模板名称</th>
                <th>模板状态</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
              {foreach $data as $v}
              <tr>
                <td>M{$v['id']}</td>
                <td>{$v['name']}模板</td>
                <td>
                    {eq name="v.status" value="0"}
                    <span class="label label-danger" onclick="handle.setStatus(this,{$v.id},1)" style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" data-title="上架">停用</span>
                    {else/}
                    <span class="label label-success" onclick="handle.setStatus(this,{$v.id},0)" style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" data-title="下架">在用</span>
                    {/eq}
                </td>
                <td>
                  <a type="button" class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="bottom" data-title="编辑" href="{:url('SnsMsg/addMsgTemplate', ['id' => $v['id']])}">
                  <i class="fa fa-pencil"></i>
                  </a>
                  <button type="button" class="btn btn-sm btn-danger"  data-toggle="tooltip" data-placement="bottom" data-title="删除" onclick="handle.delTemplate(this,{$v['id']})">
                      <i class="fa fa-trash"></i>
                  </button>
                </td>
              </tr>
              {/foreach}
            </tbody>
          </table>
      </div>
      <div class="box-footer">
        {$data->render()}
      </div>
  </div>
</section>
<script>
  var requestUrl = {
        changeStatus : "{:url('SnsMsg/setTempStatus')}",
        delTemplate  : "{:url('SnsMsg/deleteTemplate')}"
  };
  var handle = {
        setStatus : function (obj, id, status) {
            $.post(requestUrl.changeStatus,{id:id, status:status} ,function(e){
                if(e.code) {
                    if (status){
                         $(obj).parent('td').html('<span class="label label-success" onclick="handle.setStatus(this,'+id+',0)"  style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" data-title="下架">在用</span>');
                    } else {
                        $(obj).parent('td').html('<span class="label label-danger" onclick="handle.changeStatus(this,'+id+',1)" style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" data-title="上架">停用</span>');
                    }
                    $.pjax.reload("#pjax-container");
                }else {
                    bayMax.warning(e.msg);
                }
            })
        },
        delTemplate : function (obj, id) {
            $.post(requestUrl.delTemplate, {id:id} ,function(e){
                if (e.code) {
                  bayMax.msg(e.msg, function(){
                      $(obj).parents('tr').remove();
                      $.pjax.reload("#pjax-container");
                  });
                } else {
                  bayMax.warning(e.msg);
                }
            })
        }
  };
</script>

